package com.liandu.common.exception;


import com.liandu.common.Common;
import com.liandu.common.JResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalException {

    @ExceptionHandler(LDException.class)
    public JResponse LDExceptionHandler(LDException e){
        e.printStackTrace();
        if (e.getMessage().equals(Common.LOGIN_LOSS)) {
            return JResponse.loginLoss();
        }
        e.printStackTrace();
        return JResponse.fail(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public JResponse runHandler(Exception e){
        e.printStackTrace();
        return JResponse.fail("未知异常");
    }
}
